package cn.itsource.service.impl;

import cn.itsource.domain.Teacher;
import cn.itsource.mapper.TeacherMapper;
import cn.itsource.service.ITeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.annotation.Target;
import java.util.List;
@Service
public class TeacherServiceImpl implements ITeacherService {
    // spring自动注入对象
    @Autowired
    private TeacherMapper teacherMapper;
    // 判断数据操作为增还是改
    @Override
    public void save(Teacher teacher) {
        // 如果数据id为空，则是新增数据
        if (teacher.getId()==null){
            // 执行增加数据
            teacherMapper.save(teacher);
        }else {
            // 否则为修改数据
            teacherMapper.update(teacher);
        }
    }

    // 删除指定数据
    @Override
    // 根据id删除指定数据
    public void delete(Long id) {
        teacherMapper.delete(id);
    }

    // 查询指定数据
    @Override
    public Teacher get(Long id) {
        Teacher teacher = teacherMapper.get(id);
        return teacher;
    }

    // 查询所有的数据
    @Override
    public List<Teacher> getAll() {
        return teacherMapper.getAll();
    }

    // 批量删除数据
    @Override
    public void bitchInsert(List<Teacher> teachers) {
        // 删除完成后结束
        if(teachers.size()==0){
            return;
        }
        // 调用批量删除的方法
        teacherMapper.bitchInsert(teachers);
    }
}
